package operations;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements Ioperation{
    @Override
    public void work(BookList bookList) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要借阅的图书的书名");
        String inputBookName = sc.nextLine();
        int i = 0;
        for (; i < bookList.getUsedSize(); i++) {
            if(bookList.getBooks()[i].getName().equals(inputBookName) && !bookList.getBooks()[i].isBorrowed()) {
                System.out.println("借阅成功！");
                bookList.getBooks()[i].setBorrowed(true);
                break;
            }

            if(bookList.getBooks()[i].getName().equals(inputBookName) && bookList.getBooks()[i].isBorrowed()) {
                System.out.println("抱歉，该图书已被借出！");
                break;
            }
        }

        if(i == bookList.getUsedSize()) {
            System.out.println("未找到您要借阅的图书信息！");
        }
    }
}
